<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:include="fragments/easyui_insdep_head :: easyui_insdep_head" th:with="title='仓库管理'">
</head>
<body>

<table id="tt" class="easyui-datagrid" style="width:100%;height:100%"
       url="./WareGet" toolbar="#tb" pageList='[1,10,20,30,50]' singleSelect="true"
       rownumbers="true" pagination="true">
    <thead>
    <tr>
        <th field="warename" width="80">名称</th>
        <th field="waredescribe" width="160">描述</th>
        <th field="barcode" width="160">条形码</th>
    </tr>
    </thead>
</table>

<div id="tb" style="padding:3px">
    <span>名称:</span>
    <input id="warename" style="line-height:26px;border:1px solid #ccc"/>
    <span>描述:</span>
    <input id="waredescribe" style="line-height:26px;border:1px solid #ccc"/>
    <span>条形码:</span>
    <input id="barcode" style="line-height:26px;border:1px solid #ccc"/>
    <input type="checkbox" id="isFuzzy" />模糊查询
    <a href="#" class="easyui-linkbutton" plain="true" onclick="doSearch()">查找</a>
    <a href="#" class="easyui-linkbutton" plain="true" onclick="doReSet()">重置</a>
    <script type="text/javascript">
        //<![CDATA[
        function doSearch() {
            $('#tt').datagrid('load', {
                warename: $('#warename').val(),
                waredescribe: $('#waredescribe').val(),
                barcode: $('#barcode').val(),
                isFuzzy: $('#isFuzzy').is(':checked')
        });
        }
        function doReSet() {
            $('#warename').val("");
            $('#waredescribe').val("");
            $('#barcode').val();
            doSearch();
        }
        //]]>
    </script>
</div>

<div id="ajaxWin" class="easyui-window" title=""
     data-options="modal:true,collapsible:true,closed:true,maximizable:false,minimizable:false,resizable:false"
     style="width:600px;height:500px;overflow: hidden">
    <iframe id="frame" name="frame" frameborder="0" style="height:100%;width:100%; "/>
</div>

<!--用于iframe post值的隐藏表单-->
<form target="frame" id="iframepostfrom" method="post">
    <input type="hidden" name="wareid" id="ffwareid"/>
    <input type="hidden" name="warename" id="ffwarename"/>
    <input type="hidden" name="waredescribe" id="ffwaredescribe"/>
    <input type="hidden" name="barcode" id="ffbarcode"/>
</form>


<script type="text/javascript">
    //<![CDATA[
    $(function () {
        $('#ajaxWin').window({
            onBeforeClose: function () { //当面板关闭之前触发的事件
                $("#tt").datagrid("reload");
            }
        });

        var pager = $('#tt').datagrid().datagrid('getPager');	// get the pager of datagrid
        pager.pagination({
            buttons: [{
                iconCls: 'icon-add',
                handler: function () {
                    windowOpen("增加商品", "/WareAddPage");
                }
            }, {
                iconCls: 'icon-set',
                handler: function () {
                    row = $("#tt").datagrid('getSelected');

                    if (row == null) {
                        $.messager.alert('警告', '请选中需要配置标签的商品', 'info');
                        return;
                    }

                    windowOpen("标签管理", "/WareComponentManaPage", row, true);
                }
            },{
                iconCls: 'icon-edit',
                handler: function () {
                    row = $("#tt").datagrid('getSelected');

                    if (row == null) {
                        $.messager.alert('警告', '请选中需要修改的商品', 'info');
                        return;
                    }

                    windowOpen("修改商品信息", "/WareUpdatePage", row);
                }
            }, {
                iconCls: 'icon-remove',
                handler: function () {
                    row = $("#tt").datagrid('getSelected');

                    if (row == null) {
                        $.messager.alert('警告', '请选中需要删除的商品', 'info');
                        return;
                    }

                    $.messager.confirm('警告', '确定删除该商品吗', function (r) {
                        if (r) {
                            $.post("/WareDelete", {wareid: row.wareid}, function (data) {
                                var data = data == "success" ? "删除成功" : "删除失败";
                                $.messager.alert('结果', data, 'info');
                                $("#tt").datagrid("reload");
                            });
                        }
                    });
                }
            }]
        });


    });

    function windowOpen(title, ajax_url, row, isMax) {
        $('#ajaxWin').panel({title: title}).panel('restore');

        if (isMax) {
            $('#ajaxWin').panel('maximize');
        } else {
            $('#ajaxWin').panel('restore');
        }

        $("#iframepostfrom").attr("action", ajax_url);
        if (row != null) {
            $('#ffwareid').val(row.wareid);
            $('#ffwarename').val(row.warename);
            $('#ffwaredescribe').val(row.waredescribe);
            $('#ffbarcode').val(row.barcode);
        }

        $('#ajaxWin').window('open');
        $("#iframepostfrom").submit();
    }

    //]]>
</script>


</body>
</html>